package labmanager.business;

import java.util.ArrayList;

import org.apache.log4j.Logger;
import dto.ResponseDTO;
import dto.UserDTO;

public class LabManagerUser {

	private static Logger logger = Logger.getLogger(LabManagerUser.class);
	
	public ResponseDTO loginUser(String user_name, String password) {
		try {
			labmanager.database.LabManagerUser labmanager = new labmanager.database.LabManagerUser();
			return labmanager.loginUser(user_name, password);
		} catch (Exception e) {
			logger.debug("Se produjo un error en business/LabManagerUSer al consultar el usuario en base de datos. " + e );
			ResponseDTO response = new ResponseDTO();
			response.setCode(99);
			response.setMessage("Se ha producido un error.");
			return response;
		}
	}

	public ResponseDTO createUser(UserDTO request) {
		try {
			labmanager.database.LabManagerUser labmanager = new labmanager.database.LabManagerUser();
			return labmanager.createUser(request.getCode(), request.getName(), request.getLastName(), 
					request.getUserName(), request.getPassword(), request.getState(), request.getProfileId());
		} catch (Exception e) {
			logger.debug("Se produjo un error en business/LabManagerUser al crear el usuario. " + e );
			ResponseDTO response = new ResponseDTO();
			response.setCode(99);
			response.setMessage("Se ha producido un error.");
			return response;
		}
	}

	public ArrayList<String> listUsers(String where) {
		ArrayList<String> al = new ArrayList<String>();
		try {
			labmanager.database.LabManagerUser labmanager = new labmanager.database.LabManagerUser();
			return labmanager.listUsers(where);
		} catch (Exception e) {
			logger.debug("Se produjo un error en business/LabManagerUser al listar los usuarios. " + e );
			al.add("99");
			al.add("Se ha producido un error.");
			return al;
		}
	}
	
	public ResponseDTO updateUser(int code, String name, String lastName,
			String userName, String password, int state, int profileId) {
		try {
			labmanager.database.LabManagerUser labmanager = new labmanager.database.LabManagerUser();
			return labmanager.updateUser(code, name, lastName, userName, password, state, profileId);
		} catch (Exception e) {
			logger.debug("Se produjo un error en business/LabManagerUser al actualizar el usuario. " + e );
			ResponseDTO response = new ResponseDTO();
			response.setCode(99);
			response.setMessage("Se ha producido un error.");
			return response;
		}
	}

}
